package com.niit.project.controller;

import com.niit.project.service.GoodsService;
import com.niit.project.service.UserGoodsService;
import com.niit.project.service.impl.GoodsServiceImpl;
import com.niit.project.service.impl.UserGoodsServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.*;
import javax.servlet.http.*;
import java.io.IOException;

//宋依琳——用户下架商品
@WebServlet(name = "DeleteUserGoodsController", value = "/DeleteUserGoodsController")
public class DeleteUserGoodsController extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request, response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //该方法用于用户在自己的商品列表中将已上架的商品删除,同时交易广场上的用户的商品也要删除
        Integer id= Integer.valueOf(request.getParameter("id"));
        String goodname = request.getParameter("goodname");
        GoodsService goodsService = new GoodsServiceImpl();
        //调用goodService的deleteGoods方法，此方法用于将交易广场中的商品信息删除
        goodsService.deleteGoods(goodname);
        System.out.println("市场信息删除！");
        UserGoodsService userGoodsService = new UserGoodsServiceImpl();
        //调用userService的deleteGoods方法，此方法用于将用户个人货架中的商品信息删除
        userGoodsService.deleteGoods(id);
        System.out.println("个人货架信息删除！");
        response.sendRedirect(request.getContextPath()+"/UserSelfGoodsController");
    }
}
